using System;
using Base;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class StartUIManage : MonoBehaviour
{
    
    [SerializeField] private GameObject lobbyPanel;
    [SerializeField] private GameObject settingsPanel;
    [SerializeField] private GameObject mallPanel;
    [SerializeField] private GameObject characterPanel;

    [SerializeField] private Button settingButton;
    [SerializeField] private Text goldText;
    private GameObject _currentPanel;
    void Awake()
    {
        settingButton.onClick.AddListener(this.OnSettingClick);
        EventCenterManager.Instance.AddListener<UIPanelShow>(EventCommand.PanelShow,OnPanelOpenClick);
        EventCenterManager.Instance.AddListener(EventCommand.UpgradeSelect,OnGoldClick);

        _currentPanel = lobbyPanel;
        GameManager.Instance.InitData();
        OnGoldClick();
    }

    private void OnGoldClick()
    {
        goldText.text = GameManager.Instance.playerData.playerGold.ToString();
    }

    private void OnPanelOpenClick(UIPanelShow type)
    {
        switch (type)
        {
            case UIPanelShow.LobbyPanel:
                lobbyPanel.SetActive(true);
                _currentPanel.SetActive(false);
                _currentPanel = lobbyPanel;
                break;
            case UIPanelShow.SettingsPanel:
                settingsPanel.SetActive(true);
                _currentPanel.SetActive(false);
                _currentPanel = settingsPanel;
                break;
            case UIPanelShow.MallPanel:
                mallPanel.SetActive(true);
                _currentPanel.SetActive(false);
                _currentPanel = mallPanel;
                break;
            case UIPanelShow.CharacterPanel:
                characterPanel.SetActive(true);
                _currentPanel.SetActive(false);
                _currentPanel = characterPanel;
                break;
            
        }
        
    }

    private void OnSettingClick()
    {
        OnPanelOpenClick(UIPanelShow.SettingsPanel);
    }

    private void OnDisable()
    {
        EventCenterManager.Instance.RemoveListener<UIPanelShow>(EventCommand.PanelShow,OnPanelOpenClick);
        EventCenterManager.Instance.RemoveListener(EventCommand.UpgradeSelect,OnGoldClick);

    }
}
